import { defineStore } from "pinia";
import { hotSuggests, brandCategories, getHomeHouseList } from "@/service";

const useHomeStore = defineStore("home", {
  state: () => ({
    hotSuggests: [], // 热门城市
    categories: [], // 分类
    houseList: [], // 商品数据
    currentPage: 1, // 分页数据
  }),
  actions: {
    // 热门城市
    async fetchHotSuggests() {
      const res = await hotSuggests();
      this.hotSuggests = res.data;
    },

    // 选项分类
    async fetchCategories() {
      const res = await brandCategories();
      this.categories = res.data;
    },

    // 商品数据
    async fetchHomeHouseList() {
      const res = await getHomeHouseList(this.currentPage);
      this.houseList.push(...res.data);
      this.currentPage++;
    },
  },
});

export default useHomeStore;
